import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ValidationPipe, VersioningType } from '@nestjs/common';
import * as helmet from 'helmet';
import { AppModule } from './app.module';
import { appConfig } from './app.config';
import console from './common/console';
import { ErrorFilter } from './app.error.filter';

async function bootstrap() {
    const app = await NestFactory.create<NestExpressApplication>(AppModule);
    app.use(helmet());
    app.enableCors();
    app.useGlobalPipes(new ValidationPipe({
        whitelist: true
    }));
    app.enableVersioning({
        type: VersioningType.URI,
    });
    app.useGlobalFilters(new ErrorFilter());
    app.useStaticAssets(__dirname + '/../public');
    await app.listen(appConfig.port);
    console.debug(`app started at port: ${appConfig.port}`);
}

bootstrap();
